package com.xjtu.controller.admin;

import com.xjtu.dto.billRecord.BillDto;
import com.xjtu.result.PageResult;
import com.xjtu.result.Result;
import com.xjtu.service.BillService;
import com.xjtu.vo.billRecord.BillDetailVo;
import com.xjtu.vo.billRecord.BillVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/admin/billRecord")
@Slf4j
@Api(tags = "收费接口")
public class BillController {

    @Autowired
    BillService billService;

    @PostMapping
    @ApiOperation("新增收费记录")
    public Result addBillRecord(@RequestBody @Valid BillDto billDto){
        billService.insert(billDto);
        return Result.success();
    }

    @GetMapping("lists")
    @ApiOperation("查看所有收费记录/某个老人的收费记录")
    public Result<PageResult> getBillList(@RequestParam(required = false, defaultValue = "1") Integer page,
                                          @RequestParam(required = false, defaultValue = "10")Integer perPage,
                                          @RequestParam(required = false, defaultValue = "null") String elderlyName) {
        PageResult pageResult = billService.queryAll(page, perPage, elderlyName);
        return Result.success(pageResult);
    }

    @GetMapping
    @ApiOperation("查看某条收费记录的详情")
    public Result<List<BillDetailVo>> getBillDetailById(@RequestParam Integer billId) {
        Result<List<BillDetailVo>> result = billService.queryDetailById(billId);
        return result;
    }

    @DeleteMapping
    @ApiOperation("删除某条收费记录")
    public Result deleteBill(@RequestParam Long billId) {
        Result result = billService.deleteById(billId);
        return result;
    }

}
